class LetterGroup {
  final String id;
  final String title;

  const LetterGroup({
    required this.id,
    required this.title,
  });

  factory LetterGroup.fromJson(Map<String, dynamic> json) {
    return LetterGroup(
      id: json['id'],
      title: json['title'],
    );
  }

  static List<LetterGroup> jsonToList(List<dynamic> json) {
    return json.map((item) => LetterGroup.fromJson(item)).toList();
  }
}

class Tone {
  String id;
  String value;
  int toneNum;
  String aud;

  Tone({
    required this.id,
    required this.value,
    required this.toneNum,
    required this.aud,
  });

  factory Tone.fromJson(Map<String, dynamic> json) {
    return Tone(
      id: json['id'],
      value: json['value'],
      toneNum: json['toneNum'],
      aud: json['aud'],
    );
  }
}

class LetterInfo {
  final String id;
  final String value;
  final String aud;
  final List<Tone> toneList;
  final List<String> group;

  const LetterInfo({
    required this.id,
    required this.value,
    required this.aud,
    required this.toneList,
    required this.group,
  });

  factory LetterInfo.fromJson(Map<String, dynamic> json) {
    List<Tone> toneList = [];
    if (json['toneList'] != null) {
      toneList =
          json['toneList'].map<Tone>((item) => Tone.fromJson(item)).toList();
    }
    return LetterInfo(
      id: json['id'],
      value: json['value'],
      toneList: toneList,
      aud: json['aud'],
      group: List.from(json['group']),
    );
  }

  static List<LetterInfo> jsonToList(List<dynamic> json) {
    return json.map((item) => LetterInfo.fromJson(item)).toList();
  }
}
